﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;

namespace Openapi.Weibo
{
    public class ResponseResult<T> : RestResponseBase, IResponseResult<T>
    {
        public ResponseResult()
        {

        }
        public ResponseResult(IRestResponse response)
        {
            this.ContentEncoding = response.ContentEncoding;
            this.ContentLength = response.ContentLength;
            this.ContentType = response.ContentType;
            this.Cookies = response.Cookies;
            this.ErrorMessage = response.ErrorMessage;
            this.Headers = response.Headers;
            this.RawBytes = response.RawBytes;
            this.ResponseStatus = response.ResponseStatus;
            this.ResponseUri = response.ResponseUri;
            this.Server = response.Server;
            this.StatusCode = response.StatusCode;
            this.StatusDescription = response.StatusDescription;
            this.Request = response.Request;
        }
        /// <summary>
        /// 是否为预期响应结果
        /// 成功则转换用户类型T，或则返回ResponseError
        /// </summary>
        public bool IsReturnError { get; set; }

        public T SuccessData { get; set; }

        public ResponseError ErrorData { get; set; }

        public new IList<RestResponseCookie> Cookies { get; set; }

        public new IList<Parameter> Headers { get; set; }

        public static explicit operator ResponseResult<T>(RestResponse response)
        {
            return new ResponseResult<T>
            {
                ContentEncoding = response.ContentEncoding,
                ContentLength = response.ContentLength,
                ContentType = response.ContentType,
                Cookies = response.Cookies,
                ErrorMessage = response.ErrorMessage,
                Headers = response.Headers,
                RawBytes = response.RawBytes,
                ResponseStatus = response.ResponseStatus,
                ResponseUri = response.ResponseUri,
                Server = response.Server,
                StatusCode = response.StatusCode,
                StatusDescription = response.StatusDescription,
                Request = response.Request
            };
        }
    }
}
